from typing import Union

from fastapi import FastAPI
import fastapi.responses

app = FastAPI()


@app.get("/", response_class=fastapi.responses.HTMLResponse)
def read_root():
    return """
    <!DOCTYPE html>
    <html>
        <head>
            <title>FastAPI Hello World</title>
            <style>
                .title {
                    font-family: "Microsoft YaHei", "微软雅黑", sans-serif;
                    font-weight: bold;
                    font-size: 1.17em;
                    color: #333;
                }
            </style>
        </head>
        <body>
            <h3 class="title">Hello World 😄</h3>
        </body>
    </html>
    """


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)